<?php defined('SYSPATH') or die('No direct script access.');
/**
* Module Dashboard
*/
class Module_lappenyewaan_lappenyewaan {
	
	private $controller;
	private $ss;
	private $message;
	private $thesystems;
	private $mydatetime;
	private $arraylist;
	
	static function &factory() {
	   $o = new Module_lappenyewaan_lappenyewaan();
	  return $o;	
	}
	
	public function __construct()
	{
		$this->controller	= Request::current()->controller();
		$this->ss					= Session::instance();
		$this->thesystems	= Helper_theSystems::factory();
		$this->mydatetime	= Helper_MyDateTime::factory();
		$this->message		= Language_Message::factory();
		$this->arraylist	= Helper_ArrayList::factory();
	}
	
	public function lappenyewaan($id, $command)
	{
			$tglawal  = Arr::get($_REQUEST,'tglawal');	
			$tglakhir = Arr::get($_REQUEST,'tglakhir');
			$id_pelanggan = Arr::get($_REQUEST,'id_pelanggan');
		
 		$lappenyewaanlists = DB::select(
 			array('so.id','id_so'),
 			array('so.tgl','tgl'),
 			array('so.id_pembayaran','id_pembayaran'),
 			array('so.total_biaya','total_biaya'),
 			array('pbayar.id_pelanggan','id_pelanggan'),
 			array('pbayar.tgl','tgl_pembayaran')
 				
 		)
		->from(array('sales_order','so'))
		->join(array('pembayaran','pbayar'))
			->on('so.id_pembayaran','=','pbayar.id');
		if(!empty($tglawal)) {
			$lappenyewaanlists = $lappenyewaanlists->where(DB::expr('YEAR(so.tgl)'),'>=',$this->mydatetime->mktime_from_sql($tglawal,'Y'))
				->where(DB::expr('MONTH(so.tgl)'),'>=',$this->mydatetime->mktime_from_sql($tglawal,'m'))
				->where(DB::expr('DAY(so.tgl)'),'>=',$this->mydatetime->mktime_from_sql($tglawal,'d'));
		}
		if(!empty($tglakhir)) {
			$lappenyewaanlists = $lappenyewaanlists->where(DB::expr('YEAR(so.tgl)'),'<=',$this->mydatetime->mktime_from_sql($tglakhir,'Y'))
				->where(DB::expr('MONTH(so.tgl)'),'<=',$this->mydatetime->mktime_from_sql($tglakhir,'m'))
				->where(DB::expr('DAY(so.tgl)'),'<=',$this->mydatetime->mktime_from_sql($tglakhir,'d'));
		}
		if(!empty($id_pelanggan)) {
			$lappenyewaanlists = $lappenyewaanlists->where('pbayar.id_pelanggan','=',$id_pelanggan);
		}

		$lappenyewaanlists = $lappenyewaanlists->execute()->as_array();
		
		$content['title']		= 'User Administrator';
		$content['content']	= View::factory('inc/lappenyewaan')
			->set('lappenyewaanlists',$lappenyewaanlists)
			->render();
		
		return $content;
	}
	
	
	
	
}